﻿#include "OptionCommand.h"

#ifdef _DEBUG
#include "../../../Memory/GameData.h"
std::map<std::u8string, option_type> optionmap{};

bool OptionCommand_onExecute(const fast_io::vector<std::u8string>& args) {
	if (args.size() == 2) {
		if (args[1] == u8"list") {
			if (optionmap.empty()) {
				C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
												 u8"[Helium] ",
												 Utils::TextColor::YELLOW,
												 u8"OptionMap is empty!");
				return true;
			}
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::WHITE,
											 u8"OptionMap List:");
			for (auto& i : optionmap) {
				if (i.second.type == 0) {
					C_GuiData::displayClientMessageC(Utils::TextColor::GRAY,
													 i.first,
													 Utils::TextColor::WHITE,
													 u8" : ",
													 Utils::TextColor::GRAY,
													 fast_io::mnp::boolalpha(i.second._bool));
				} else if (i.second.type == 1) {
					C_GuiData::displayClientMessageC(Utils::TextColor::GRAY,
													 i.first,
													 Utils::TextColor::WHITE,
													 u8" : ",
													 Utils::TextColor::GRAY,
													 i.second._int);
				} else if (i.second.type == 2) {
					C_GuiData::displayClientMessageC(Utils::TextColor::GRAY,
													 i.first,
													 Utils::TextColor::WHITE,
													 u8" : ",
													 Utils::TextColor::GRAY,
													 i.second._float);
				} else {
					fast_io::fast_terminate();
				}
			}
		} else {
			return false;
		}
	} else if (args.size() == 3) {
		if (args[1] != u8"cancel")
			return false;
		auto find = optionmap.find(args[2]);
		if (find != optionmap.end()) {
			optionmap.erase(find);
			C_GuiData::displayClientMessageC(Utils::TextColor::LIGHT_PURPLE,
											 u8"[Helium] ",
											 Utils::TextColor::GREEN,
											 u8"ERASE!");
		} else {
			return false;
		}
	} else if (args.size() == 5) {
		if (args[1] != u8"modify") 
			return false;
		if (args[3] == u8"bool") {
			bool w{};
			if (args[4] == u8"true") {
				w = true;
			} else if (args[4] == u8"false") {
				w = false;
			} else {
				return false;
			}
			optionmap[args[2]] = option_type{.type = 0, ._bool = w};
		} else if (args[3] == u8"int") {
			optionmap[args[2]] = option_type{.type = 1, ._int = ICommand::assertInt(args[4])};
		} else if (args[3] == u8"float") {
			optionmap[args[2]] = option_type{.type = 2, ._float = ICommand::assertFloat(args[4])};
		} else {
			return false;
		}
	} else {
		return false;

	}
	return true;
}

ICommand OptionCommand{u8"option",
					   u8".option modify <option> <bool, int, float> <select>, list, cancel <option>",
					   {u8"Modify game options", u8"修改游戏选项", u8"修改遊戲選項", u8"ゲームオプションを変更する"},
					   {},
					   fast_io::vector<aliasList_struct>{},  // If empty must use fast_io::vector<aliasList_struct>{}
					   nullptr,
					   &OptionCommand_onExecute};
#endif